class ItemReviewVotesController < ApplicationController
  #商品品论的投票
#  before_filter :login_required

  def index
    render :text => "2222222222"
  end

  def create
    @review_vote = User.first.item_review_votes.find_by_item_review_id(params[:review_id]) || User.first.item_review_votes.build(:item_review_id => params[:review_id],:vote => params[:vote] )
    #    @review_vote.valid?
    if @review_vote.save
      flash[:notice]= "投票成功！"
    else
      flash[:error]= "是否已经投票过了！"
    end
    up_vote = ItemReviewVote.count(:conditions => ["item_review_id = ? and vote = 1",@review_vote.item_review_id])
    down_vote = ItemReviewVote.count(:conditions => ["item_review_id = ? and vote = -1",@review_vote.item_review_id])
    render :json => {:up_vote => up_vote, :down_vote => down_vote}.to_json
  end

end
